#ifndef PROCESSTABLE_H
#define PROCESSTABLE_H

#include <gtkmm.h>
#include <vector>
#include <string>
#include "processinfo.h"

class ProcessTable : public Gtk::ScrolledWindow {
public:
    ProcessTable();
    virtual ~ProcessTable();
    
    void update_data(const std::vector<ProcessInfo>& processes);
    int get_selected_pid() const;
    void set_selected_pid(int pid);
    Glib::RefPtr<Gtk::TreeSelection> get_selection();  // 添加获取选择对象的方法
    
protected:
    // 信号处理
    void on_selection_changed();
    bool on_button_press_event(GdkEventButton* event);
    
    // 右键菜单处理
    void on_end_task();
    void on_end_process_tree();
    void on_open_directory();
    void on_show_properties();
    void on_copy_command_line();  // 添加复制命令行功能
    
    class ModelColumns : public Gtk::TreeModel::ColumnRecord {
    public:
        ModelColumns() {
            add(m_col_name);
            add(m_col_pid);
            add(m_col_status);
            add(m_col_user);
            add(m_col_cpu);
            add(m_col_memory);
            add(m_col_time);
            add(m_col_command);
            add(m_col_priority);
            add(m_col_disk_read);
            add(m_col_disk_write);
            add(m_col_network_recv);
            add(m_col_network_send);
        }
        
        Gtk::TreeModelColumn<std::string> m_col_name;
        Gtk::TreeModelColumn<int> m_col_pid;
        Gtk::TreeModelColumn<std::string> m_col_status;
        Gtk::TreeModelColumn<std::string> m_col_user;
        Gtk::TreeModelColumn<std::string> m_col_cpu;
        Gtk::TreeModelColumn<std::string> m_col_memory;
        Gtk::TreeModelColumn<std::string> m_col_time;
        Gtk::TreeModelColumn<std::string> m_col_command;
        Gtk::TreeModelColumn<int> m_col_priority;
        Gtk::TreeModelColumn<std::string> m_col_disk_read;   // 磁盘读取列
        Gtk::TreeModelColumn<std::string> m_col_disk_write;  // 磁盘写入列
        Gtk::TreeModelColumn<std::string> m_col_network_recv; // 网络接收列
        Gtk::TreeModelColumn<std::string> m_col_network_send; // 网络发送列
    };
    
    ModelColumns m_columns;
    Glib::RefPtr<Gtk::ListStore> m_ref_tree_model;
    Gtk::TreeView m_tree_view;

    // 右键菜单
    Glib::RefPtr<Gtk::Menu> m_popup_menu;
    
    // 当前选中的进程信息
    int m_selected_pid;
    std::string m_selected_process_name;
};

#endif // PROCESSTABLE_H